package com.baozun.houji.me.viewmodel

import androidx.lifecycle.MutableLiveData
import com.baozhun.mall.common.model.bean.AddressInfo
import com.baozun.houji.me.network.mMeApiService
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.ext.request

/**
 * @Title：
 * @Description：
 * @Author：xing.luo
 * @Since：2022/12/16
 * @Version：1.0.0
 */
class AddressListViewModel : BaseViewModel() {

    val addressList = MutableLiveData<MutableList<AddressInfo>>()
    val defaultResult = MutableLiveData<Any>()

    fun getAddressList() {
        request({ mMeApiService.getAddressList() }, {
            addressList.postValue(it)
        }, {
        }, isShowDialog = true)
    }

    fun setDefaultAddress(addressInfo: AddressInfo) {
        addressInfo.is_default = 1
        request({ mMeApiService.saveAddress(addressInfo) }, {
            defaultResult.postValue(it)
        }, {

        }, isShowDialog = true)
    }
}